package model;

import java.util.ArrayList;
public class OrderContainer
{
 private static ArrayList<Order>OrderCollection;
 private static OrderContainer instance;
  public OrderContainer()
  {
      OrderCollection=new ArrayList<Order>();
      
  }
 public static void addOrder(Order order)
 {
     OrderCollection.add(order);
 }
 public static OrderContainer getInstance()
{
 if (instance==null) 
    {
     instance= new OrderContainer();
    }
    return instance;
}
 public Order findOrder(String number) {
    Order order=null;
    int index=0;
    boolean found=false;
    while(index < OrderCollection.size() && !found) {
       order=OrderCollection.get(index);
        if(order.getNumber().equals(number)) {
            found=true;
        } else {
            index++;
        }
    }
    if(found) {
        return OrderCollection.get(index);
    } else {
        return null;
    }
}  
public void removeOrder(String number)
 {
 Order order=findOrder(number); 
        if(order !=null){
            boolean ok=OrderCollection.remove(order);
            if(ok){
                System.out.println("Order number:  " + number + " is now deleted");
                  } 
                }
            else{ System.out.println("There is no order with the number: " + number);
                }
           }
            public void printOrder()
 {
     System.out.println("List of orders: ");
     for(Order order:OrderCollection)
     {System.out.println(""+ order.getNumber());
      System.out.println("");
     
 } }
           
 } 
